package com.salton123.charging.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.salton123.charging.Consts
import com.salton123.charging.media.VideoPlayerHelper
import com.salton123.log.XLog

/**
 * User: wujinsheng1@yy.com
 * Date: 2020/9/30 16:47
 * ModifyTime: 16:47
 * Description:
 */
class BatteryStatusReceiver : BroadcastReceiver() {
    var mPlayer = VideoPlayerHelper.getInstance()

    override fun onReceive(context: Context, intent: Intent) {
        XLog.i(TAG, "收到广播：" + intent.action!!)
        if ("android.intent.action.BATTERY_CHANGED" == intent.action) {   //电量变化
            if (!mPlayer.isPlaying) {
                mPlayer.stop()
                mPlayer.path("res://" + Consts.INTERNAL_RAW_SOUNDS[0])
                mPlayer.start()
            }
        } else if ("android.intent.action.ACTION_POWER_DISCONNECTED" == intent.action) {   //电量变化
//            if (!mPlayer.isPlaying) {
//                mPlayer.path("res://" + Consts.INTERNAL_RAW_SOUNDS[0])
//                mPlayer.start()
//            }
        }
    }

    private fun stopPlay() {
        mPlayer.stop()
    }

    companion object {
        val TAG = "BatteryStatusReceiver"
    }
}
